//列表页
$(function () {

    var total = 10
    // 分页参数
    var params = {
        pagenum: 1,
        pagesize: 6
    }
    //列表内容
    var arr = [`<div class="kr_news_date">
17 <span>08月</span>
</div>`]
    //列表数据
    function loadList() {

        $.ajax({
            type: 'GET',
            url: 'http://localhost:8888/api/articles',
            data: params,
            success: function (res) {
                total = res.total

                console.log(res);
                if (res.status === 1) {
                    return layer.msg('没有更多数据了')
                }
                if (res.status === 0) {
                    total = res.total
                    var str = ""

                    res.data.forEach(function (item) {
                        let arr = item.pub_date.split("T")
                        var time = arr.join("  ")
                        time = time.substring(0, time.length - 5)
                        str += `
                            <div class="item">
                            <h4>
                              <a href="detail.html?id=${item.id}">${item.title}</a>
                            </h4>
                            <p class="meta">
                              <span>${time}</span>
                              <a href="javascript:;" class="wechat"></a>
                              <a href="javascript:;" class="weibo"></a>
                            </p>
                            <p class="brief">${item.content}</p>
                          </div>
                            `
                    })
                    $('.kr_news_list').append(str)
                }
            }
        })
    }

    loadList()

    // 加载更多数据
    $('.kr_more').click(function () {
        params.pagenum += 1
        loadList()
    })
})